package server

import (
	"distributed/conf"
	"distributed/message"
	"net/rpc"
)

type StorageClient struct {
	client *rpc.Client
}

var storageClient *StorageClient

func ConnectStorage() {
	var err error
	storageClient = &StorageClient{}
	storageClient.client, err = rpc.DialHTTP("tcp", conf.GetConfig("storage_url"))
	if err != nil {
		panic(err)
	}
}

func storeRecord(req message.ReptileResult, function string) error {
	var result message.ReptileResp
	if err := storageClient.client.Call("Store."+function, req, &result); err != nil {
		return err
	}
	//fmt.Println("[ storeRecord ]", result)
	return nil
}
